package cn.hongyu.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

@Component("aspect")
@Aspect//告知spring当前类是切面类
public class MyAspect {
    //切点表达式抽取
    @Pointcut(value = "execution(* cn.hongyu.target.Target.*(..))")
    public void pointcut(){}

    @Before("pointcut()")//配置前置增强
    public void before(){
        System.out.println("before前置通知.......");
    }
    @After("MyAspect.pointcut()")
    public void after(){
        System.out.println("after最终通知............");
    }
    @AfterReturning("execution(* cn.hongyu.target.Target.*(..))")
    public void afterReturning(){
        System.out.println("afterReturning后置通知......");
    }
    @AfterThrowing("execution(* cn.hongyu.target.Target.*(..))")
    public void afterThrowing(){
        System.out.println("afterThrowing异常抛出通知......");
    }
    //ProceedingJoinPoint pjp正在执行的连接点
    @Around("execution(* cn.hongyu.target.Target.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around前环绕通知......");
        Object proceed = pjp.proceed();
        System.out.println("around后环绕通知......");
        return proceed;
    }}
